package cn.tedu.doc_sys.controller;

import cn.tedu.doc_sys.pojo.dto.RegisterAddNewDTO;
import cn.tedu.doc_sys.pojo.dto.RegisterLoginInfoDTO;
import cn.tedu.doc_sys.service.IRegisterService;
import cn.tedu.doc_sys.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "01. 管理员管理模块")
@RestController
@RequestMapping("/register")
public class RegisterController {

    @Autowired
    IRegisterService iRegisterService;


    @ApiOperation("登陆管理员")
    @ApiOperationSupport(order = 50)
    @PostMapping("/login")
    public JsonResult login(RegisterLoginInfoDTO registerLoginInfoDTO){
        iRegisterService.selectLogin(registerLoginInfoDTO);
        return JsonResult.ok();
    }
    /**
     * 新增管理员
     * @param registerAddNewDTO
     * @return
     */
    @ApiOperation("添加管理员")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(RegisterAddNewDTO registerAddNewDTO){
        iRegisterService.addNew(registerAddNewDTO);
        return JsonResult.ok();
    }

    /**
     * 根据id删除管理员
     * @param officeId
     * @return
     */
    @ApiOperation("删除管理员")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name="id",value = "管理员id",required = true)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long officeId ){
        log.debug("开始处理删除管理员的业务，{}",officeId);
        iRegisterService.delete(officeId);
        return JsonResult.ok();
    }



}
